'''
    自动取款机
    1.登录
    2.退出
    3.查询余额
    4.取钱
    5.存钱
    6.界面
'''
user_list = [
    {'name': '001', 'psw': '123'},
    {'name': '002', 'psw': '456'},
    {'name': '003', 'psw': '789'},
]
money_list = [
    {'name': '001', 'money': '100'},
    {'name': '002', 'money': '200'},
    {'name': '003', 'money': '300'},
]

def login():
    name = input('请输入账号：')
    psw = input('请输入密码：')
    for user in user_list:
        if name == user['name']:
            if psw == user['psw']:
                print('登录成功')
                return name

    print('账号密码错误，请输出正确账号密码，或重新注册')
    print('='*60)
    login()


def logout():
    print('再见')
    print('='*60)
    go()


def show_money(name):
    for dict_money in money_list:
        if dict_money['name'] == name:
            money = dict_money['money']
    print('你的余额：', money)

def take_money(name):
    global money
    take = int(input('请输入你要取的金额：'))
    for dict_money in money_list:
        if dict_money['name'] == name:
            if take <= int(dict_money['money']):
                money = int(dict_money['money']) - take
                dict_money['money'] = money
                print('你的余额：', money)
            # 判断取的金额是否超过余额
            else:
                print('输入错误，余额不足。')
                print('='*60)
                take_money(name)

def save_money(name):
    save = input('请输入你要存的金额：')
    for dict_money in money_list:
        if dict_money['name'] == name:
            money = int(dict_money['money']) + int(save)
            dict_money['money'] = money
    print('你的余额：', money)

def go():
    name = login()
    while True:

        print('='*20, '自动取款机', '='*20)
        print('{:1}{:10}{:13}'.format('', '1.查看余额', '2.取钱'))
        print('{:1}{:12}{:13}'.format('', '3.存钱', '4.退出'))
        print('='*40)
        key = int(input('请输入你要的操作：'))
        if key == 1:
            show_money(name)
        if key == 2:
            take_money(name)
        if key == 3:
            save_money(name)
        if key == 4:
            logout()

go()